home *** CD-ROM | disk | FTP | other *** search
- .Na "dbmsghandle"
- .Aa
- .Fu
- Install a user function to handle \*S messages.
- .Ih "message handler, installing"
- .Ih "\*S messages"
- .Ih "messages, \*S"
- .Sy
- .Sf "int (*dbmsghandle(handler))()"
- .Sp "int" "(*handler)()"
- .Co
- .Bl
- \f2dbmsghandle()\f1 installs a message-handler function that you supply.
- When \*L receives a \*S error or informational message, it will
- call this message handler immediately.
- You must install a message handler
- in order to handle \*S messages properly.
- .Bl
- If the command buffer contains just a single command and that command provokes
- a \*S message, \*L will call the message handler during \f2dbsqlexec()\f1.
- If the command buffer contains multiple commands and one of the commands provokes
- a \*S message, \*L will call the message handler when
- \f2dbresults()\f1 is called for the particular command.
- .Bl
- You can de-install an existing message handler by calling \f2dbmsghandle()\f1 with a
- NULL parameter.
- You can also, at any time, install a new message handler.
- The new handler will automatically replace any existing handler.
- .Bl
- See the \f2\*S Reference Supplement\f1 for a list of \*S messages.
- In addition, the \*N PRINT and RAISERROR commands generate \*S messages
- that \f2dbmsghandle()\f1 will catch.
- .Bl
- Another routine, \f2dberrhandle()\f1, installs an error handler that \*L calls
- in response to \*L errors.
- If the application provokes messages from \*L and \*S simultaneously,
- \*L calls the \*S message handler before it calls the \*L error handler.
- .mc |
- .Bl
- The routines \f2dbsetuserdata()\f1 and \f2dbgetuserdata()\f1 can be
- particularly useful when you need to transfer information between
- the message handler and the program code that triggered it.
- See the \f2dbsetuserdata()\f1 manual page for an example of
- how to handle deadlock in this way.
- .mc
- .Bz
- .Pa
- .Pi handler
- A pointer to the user function that will be called whenever
- \*L receives an error or informational message from \*S.
- \*L calls this function
- with eight parameters:
- .sp
- .in +10n
- .ta +10n
- .ti -10n
- \f2dbproc\f1 The affected DBPROCESS.
- .sp 0.5v
- .ti -10n
- \f2msgno\f1 The current message's number (datatype \f2DBINT\f1).
- These numbers are documented in the \f2\*S Reference Supplement\f1.
- .sp 0.5v
- .ti -10n
- \f2msgstate\f1 The current message's error state number (datatype \f2int\f1).
- These numbers provide Sybase Customer Support with information about the context of the error.
- .sp 0.5v
- .ti -10n
- \f2severity\f1 The current message's information class or error severity (datatype \f2int\f1).
- These numbers are documented in the \f2System Administration Guide\f1.
- .sp 0.5v
- .ti -10n
- \f2msgtext\f1 The null-terminated text of the current message (datatype \f2char *\f1).
- .sp 0.5v
- .mc |
- .ti -10n
- \f2srvname\f1 The null-terminated name of the server that generated the message
- (datatype \f2char *\f1).
- A server's name is
- stored in the \f2srvname\f1 column of its \f2sysservers\f1 system table.
- It is used in server-to-server communication; in particular, it's used
- when one server logs into another server to perform a remote procedure call.
- If the server has no name, \f2srvname\f1 will be of length 0.
- .sp 0.5v
- .ti -10n
- \f2procname\f1 The null-terminated name of the stored procedure
- that generated the message (datatype \f2char *\f1).
- If the message was not generated by a stored procedure, \f2procname\f1 will be of length 0.
- .sp 0.5v
- .ti -10n
- \f2line\f1 The number of the command batch or stored procedure line that
- generated the message (datatype \f2DBUSMALLINT\f1).
- Line numbers start at 1.
- The line number pertains to the nesting level at which the message was generated.
- For instance, if a command batch executes stored procedure A, which then calls
- stored procedure B, and a message is generated at line 3 of B, then \f2line\f1 will be 3.
- .sp 0.5v
- \f2line\f1 will be 0 if there is no line number associated with the message.
- Circumstances that could generate messages without line numbers include
- a login error or a remote procedure call (performed via \f2dbrpcsend()\f1)
- to a stored procedure that doesn't exist.
- .sp
- .in -10n
- The message handler must return a value of 0 to \*L.
- .sp
- .mc
- The following example shows a typical message handler routine:
- .ta +4n +4n +4n +4n +4n +4n
- .SD
- .mc |
- .so dbmsghandle.ex
- .mc
- .ED
- .in -.375i
- .Re
- .br
- A pointer to the previously-installed message handler.
- This may be NULL.
- .Sa
- dberrhandle,
- dbgetuserdata,
- dbsetuserdata
-